// 定义一个中间件
const express = require('express');
const { URLSearchParams } = require('url');
const app = express();

// app.use((req, res, next) => {
//   let str = '';
//   req.on('data', chunk => {
//     str += chunk;
//   })
//   req.on('end', () => {
//     console.log('str:',str)
//     let body = new URLSearchParams(str);
//     let a = [...body.keys()];
//     let b = [...body.values()];
//     let obj = {};
//     a.forEach((item,index) => {
//       obj[item] = b[index];
//     });
//     console.log('obj:',obj)
//     req.obj1 = obj
//   })
//   next();
// });
app.use(express.urlencoded({extended:false}))
app.use(express.json())

app.post('/user', (req, res) => {
  console.log('req.body:',req.body)
  res.send(req.body);
});

app.listen(3000, () => {
  console.log('success');
});